const result = require('./handle')
class checking {
  constructor(ctx, ...obj) {
    this.ctx = ctx
    this.obj = obj
    // console.log(obj)
  }
  //校验前端传入的值
  Errunder() {
    let bvc = this.obj.indexOf(undefined)
    console.log(bvc)
    if (bvc != -1) {
      console.log('jmx')
      throw new result('参数填写错误', 400)
    }
  }
  //  校验手机号码
  Phone(moblie, num) {
    let phone = /^1[3456789]\d{9}$/
    if (!phone.test(this.obj[num])) {
      console.log('校验手机号码')
      throw new result(moblie, 202)
    }
  }
  //密码校验6-20位
  Password(pass, num) {
    let reg = /^(?![\d]+$)(?![a-zA-Z]+$)(?![^\da-zA-Z]+$).{6,20}$/
    if (!reg.test(this.obj[num])) {
      console.log('校验密码')
      throw new result(pass, 202)
    }
  }
}
class regChecking extends checking {
  start() {
    super.Errunder()
    super.Phone('请填写正确的手机号码', 0)
    super.Password('密码必须由6-20位数字和字母的组合', 1)
  }
}

module.exports = { checking, regChecking }
